import EventCenter from "../../TFrame/script/helper/EventCenter";
import EventNames from "../EventNames";
import CoinSystem from "../system/CoinSystem";
import GameLogicController from "./GameLogicController";
import StatusProperties from "./StatusProperties";

const { ccclass, property } = cc._decorator;

@ccclass
export default class HintButton extends cc.Component {

    protected onLoad(): void {
        EventCenter.once(EventNames.DiffAllFound, () => {
            let btn = this.node.getComponent(cc.Button);
            btn && (btn.enabled = false);
            this.node.active = false;
        }, this);
        //初始化重置一下状态
        StatusProperties.hintAliving = false;

        this.updateText();

        EventCenter.on(EventNames.ConsumeCoins, () => {
            if (CoinSystem.coinInMomory < CoinSystem.TIP_COIN) {
                this.updateText();
            }
        }, this)
    }

    updateText() {
        this.node.getChildByName("gold").active = (CoinSystem.coinInMomory >= CoinSystem.TIP_COIN);
        this.node.getChildByName("coinNum").active = (CoinSystem.coinInMomory >= CoinSystem.TIP_COIN);
        this.node.getChildByName("text").active = !this.node.getChildByName("coinNum").active
    }

    click() {
        if (StatusProperties.hintAliving == true)
            return;
        GameLogicController.getInstance().hintClick();
    }
}
